<template>
  <div class="follow-up-card">
    <!-- 顶部tab切换栏 -->
    <!-- 折叠面板 -->
    <div v-if="historyList.length>0">
      <el-collapse
        accordion
        v-model="activeNames"
        class="follow-up-collapse"
        v-show="isExpanded"
      >
        <el-collapse-item
          :name="index"
          v-for="(item, index) in historyList"
          style="border-bottom: 1px solid #dddddd"
          :key="index"
        >
          <template #title>
            <div style="padding: 0 10px">
              {{ item.projectName }}
              <span style="float: right">{{
                item.examTime?.split(' ')[0]
              }}</span>
            </div>
          </template>
          <div class="right-card-content">
            <div class="right-card-content-title">报告影像</div>
            <div
              class="right-card-content-noimg"
               style="display: grid; grid-template-columns: repeat(3, 72px); gap: 10px;"

              v-if="item.examImageList"
            >
              <img
                :src="items"
                v-for="(items, index2) in item.examImageList.split(',')"
                @click="selectImg(item.examImageList.split(','), index2)"
                :key="index"
                style="
                  object-fit: contain;
                  margin-bottom: 10px;
                  width: 72px;
                  height: 72px;
                  background: #dcdcdc;
                "
                alt=""
              />
            </div>
            <div class="dashed"></div>
            <div class="right-card-content-title" style="margin-top: 10px">
              查验描述
            </div>
            <div class="right-card-content-item">
              <div>{{ item.examDesc }}</div>
            </div>
            <div class="dashed"></div>
            <div class="right-card-content-title" style="margin-top: 10px">
              诊断意见
            </div>
            <div class="right-card-content-item">
              <div>
                {{ useBaseDataStore.getEnumData(item.diagnosisFlag,'diagnosisFlagEnum')}}
              </div>
            </div>
            <div class="dashed"></div>
            <div class="right-card-content-title" style="margin-top: 10px">
              制单信息
            </div>
            <div class="right-card-content-item">
              <div>检查人员：{{ item.examEmpName }}</div>
              <div>检查时间：{{ item.examTime }}</div>
              <div>审核人员：{{ item.auditBy }}</div>
              <div>审核时间：{{ item.auditTime }}</div>
              <div>审核意见：{{ item.refuseReason }}</div>
            </div>
          </div>
        </el-collapse-item>
      </el-collapse>
    </div>

    <ImgYl
      :visible="Imgvisible"
      v-if="Imgvisible"
      :images="images"
      :initialIndex="initialIndex"
      :onClose="handleImgClose"
    />
  </div>
</template>

<script lang="ts" setup>
import emptyImage from '@/assets/icon/internet_empty_illustration.svg';
import { ref, computed } from 'vue';
import stores from '@/store';
import store from '@/store';
const useBaseDataStore = store.useBaseDataStore();
const followupChannel = ref(
  useBaseDataStore.getEnumSelect('followupChannelEnum')
);
const props = defineProps<{
  historyList: any;
}>();
const sideTypeEnum = ref<any>(
  stores.useBaseDataStore().getEnumSelect('acupointSideTypeEnum')
);

const sideTypeEnumText = (val: any) => {
  for (let index = 0; index < sideTypeEnum.value.length; index++) {
    let item = sideTypeEnum.value[index];
    if (val == item.value) {
      return item.text;
    }
  }
};
//图片列表
const images = ref<any[]>([]);
const Imgvisible = ref<boolean>(false);
const initialIndex = ref<number>(0);
const selectImg = (list: any, index: number) => {
  let img: any = [];
  list.forEach((item: any) => {
    img.push({
      thumbnailUrl: item,
      url: item,
      alt: '缩略图',
    });
  });
  images.value = img;
  initialIndex.value = index;
  Imgvisible.value = true;
};
// 直接派生，避免副本与时序问题

// const historyList = ref([
//   {
//     followupId: 6, //随访ID
//     visitNo: '20250801000920010', //诊号;唯一诊号
//     visitDate: '2025-08-01', //就诊日期yyyy-MM-dd
//     followupDate: '2025-08-04', //计划随访日期
//     followupStatus: '2', //随访状态 followupStatusEnum
//     realFollowupDate: '2025-08-04', //实际随访日期
//     followupEmpId: 10, //随访人ID
//     followupEmpName: '王医生的助理', //随访人姓名
//     followupResult: '无异常', //随访结果
//   },
//   {
//     followupId: 6, //随访ID
//     visitNo: '20250801000920010', //诊号;唯一诊号
//     visitDate: '2025-08-01', //就诊日期yyyy-MM-dd
//     followupDate: '2025-08-04', //计划随访日期
//     followupStatus: '2', //随访状态 followupStatusEnum
//     realFollowupDate: '2025-08-04', //实际随访日期
//     followupEmpId: 10, //随访人ID
//     followupEmpName: '王医生的助理', //随访人姓名
//     followupResult: '无异常', //随访结果
//   },
// ]);
// 顶部tab数据与选中状态
const tabs = [{ label: '随访记录', value: 'history' }];
const activeTab = ref('history');

// 折叠面板控制
const activeNames = ref(['1']);
const isExpanded = ref(true); // 控制折叠面板显示/隐藏
const handleImgClose = () => {
  Imgvisible.value = false;
};
// 切换折叠状态
const toggleCollapse = () => {
  isExpanded.value = !isExpanded.value;
};
</script>

<style scoped lang="scss">
:deep(.el-collapse-item__header) {
  border-radius: 6px;
  background: rgba(253, 253, 253, 0.6);
}

:deep(.el-collapse-item__arrow) {
  transition: transform 0.3s ease;
  transform: rotate(-90deg); /* 默认状态(关闭时)向上 */
}

:deep(.el-collapse-item__arrow.is-active) {
  transform: rotate(90deg); /* 展开状态(打开时)向下 */
}

:deep(.el-collapse-item__content) {
  padding: 16px 8px 16px 8px;
  background: #f8f8f8;
  border-radius: 0 0 6px 6px;
  border-radius: 6px 6px 6px 6px;
  border: 1px solid #dcdcdc;
}

.collapse-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.diagnosis {
  color: #333;
  font-weight: bold;
  font-size: 13px;
}

.action-btn {
  font-size: 14px;
  color: #00b3b3;
  cursor: pointer;
}

.collapse-content {
  font-size: 11px;
  line-height: 1.6;
}

/* 自定义随访卡片样式：标题行与内容的虚线分隔、复制按钮样式、对齐与留白 */
.collapse-content .collapse-title.info-row {
  padding: 4px 0 10px;
  margin-bottom: 10px;
  border-bottom: 1px dashed #e6e6e6;
}

/* 右侧“复制”样式与交互反馈 */
.collapse-content .collapse-title .diagnosis:last-child {
  font-size: 11px;
  color: #18b3ab;
  cursor: pointer;
  user-select: none;
}
.collapse-content .collapse-title .diagnosis:last-child:hover {
  opacity: 0.85;
}

/* 信息行排版更贴近设计稿 */
.collapse-content .info-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.collapse-content .label {
  color: #666;
  font-size: 12px;
}

.info-row {
  margin-bottom: 8px;
}

.label {
  color: #666;
  margin-right: 8px;
  min-width: 80px;
  flex-shrink: 0;
}

.value {
  color: #333;
  flex: 1;
}
.tcm-box {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px dashed #dcdcdc;
  gap: 0;
}
.tcm-box .info-row {
  width: 33.33%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 0;
  padding: 8px 0;
}
.tcm-box .label {
  font-size: 14px;
  color: #666;
  display: flex;
  align-items: center;
  gap: 4px;
}
.card-title {
  width: 280px;
  height: 52px;
  border-radius: 0px 0px 0px 0px;
  font-family: Microsoft YaHei, Microsoft YaHei;
  font-weight: 600;
  font-size: 16px;
  color: rgba(0, 0, 0, 0.9);
  line-height: 22px;
  padding-left: 17px;
  line-height: 52px;
  border-bottom: 1px solid #dddddd;
  background: rgba(253, 253, 253, 0.6);
  text-align: left;
}
.overflow {
  width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.right-card-container {
  width: 22%;
  height: 100%;
  margin-left: 17px;
  .right-card {
    width: 100%;
    height: 100%;
    overflow: auto;
    .right-card-title {
      width: 100%;
      border-radius: 0px 0px 0px 0px;
      font-family: Microsoft YaHei, Microsoft YaHei;
      font-weight: 600;
      font-size: 16px;
      color: rgba(0, 0, 0, 0.9);
      padding: 15px 17px;
      line-height: 22px;
      border-bottom: 1px solid #e7e7e7;
      text-align: left;
      font-style: normal;
      text-transform: none;
    }
    .right-card-content {
      border-radius: 6px 6px 6px 6px;
      border: 1px solid #dcdcdc;
      padding: 8px 10px;
      .right-card-content-title {
        width: 248px;
        line-height: 22px;
        font-weight: bold;
        font-size: 11px;
        color: rgba(0, 0, 0, 0.6);
        text-align: left;
        font-style: normal;
        text-transform: none;
      }
      .dashed {
        border-bottom: 1px dashed #dcdcdc;
        margin-top: 10px;
      }
      .right-card-content-item {
        font-weight: 400;
        font-size: 11px;
        color: rgba(0, 0, 0, 0.6);
        line-height: 18px;
        text-align: left;
        font-style: normal;
        text-transform: none;
      }
    }
    .right-card-content-noimg {
      width: 72px;
      height: 72px;
      margin: 5px 0;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
}
.dashed {
  border-bottom: 1px dashed #dcdcdc;
  margin-top: 10px;
}
.follow-up-collapse {
  border: none;
  // padding: 0px 16px 10px 16px;
}
</style>
